#!/bin/bash

#
# Load XML table from $1 (filename.ctl_tab)
#

list=`ls $CONFS_DIR/$REF_DIR/$1 | sed 's/\(.*\)\..*/\1/'`

rm -f $ETL_HOME/$REF_DIR.dat
echo '----------------------------------------------------------------------------------------------------------------------------'

for i in $list
do
 echo '----------------------------------------'
 echo 'TAB'
 echo $i
 echo '----------------------------------------'

 $SCRIPTS_DIR/enum_replace.sh `basename $i`.ctl_tab $ETL_HOME $REF_DIR $X_TMP_DIR

 mknod $ETL_HOME/$REF_DIR.dat p

 sqlplus $TARGET_SCHEMA @$SCRIPTS_DIR/truncate.sql `cat $i.ctl_tab  | grep 'into table' | sed 's/into table//g'`

 export myselect=`cat $i.ctl_tab.final  | grep '\-\-SQL:' | sed 's/--SQL://g'`
 export mydirect=`cat $i.ctl_tab.final  | grep '\-\-DIRECT:' | sed 's/--DIRECT://g'`

 mysql $MYSQL_SCHEMA --host=$MYSQL_HOST --user=$MYSQL_UNAME --password=$MYSQL_PASSWD --quick --default-character-set=utf8 -e "${myselect}" > $ETL_HOME/$REF_DIR.dat&


 sqlldr $TARGET_SCHEMA control=$i.ctl_tab.final DATA=$ETL_HOME/$REF_DIR.dat DIRECT=$mydirect LOG=$LOG_DIR/$REF_DIR/tab\_`basename $i`.log COLUMNARRAYROWS=100 SKIP=1 ROWS=100000 BINDSIZE=100000000
 rm -f $ETL_HOME/$REF_DIR.dat
done


